package top.songxs.gmall.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import top.songxs.gmall.common.result.Result;
import top.songxs.gmall.feign.item.SkuDetailFeignClient;
import top.songxs.gmall.product.vo.SkuDetailVo;

@Controller
public class ItemController {

    @Autowired
    private SkuDetailFeignClient skuDetailFeignClient;
    @GetMapping(value = "/{skuId}.html")
    public String item(@PathVariable(value = "skuId") Long skuId, Model model) {


        // 通过feign远程调用service-item服务的接口获取数据
        Result<SkuDetailVo> skuDetailVoResult = skuDetailFeignClient.getSkuDetailList(skuId);
        SkuDetailVo detailVoResultData = skuDetailVoResult.getData();

        // 将数据存储到model对象中
        model.addAttribute("categoryView", detailVoResultData.getCategoryView());

        // 将skuInfo数据保存到model对象中
        model.addAttribute("skuInfo", detailVoResultData.getSkuInfo());

        // 将价格数据存储到Model对象中
        model.addAttribute("price", detailVoResultData.getPrice());

        // 将spu的销售属性存储到model对象中
        model.addAttribute("spuSaleAttrList", detailVoResultData.getSpuSaleAttrList());


        model.addAttribute("valuesSkuJson", detailVoResultData.getValuesSkuJson());
        return "item/index";
    }
}
